package com.itheima.backstage.manager;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.itheima.domain.db.Log;
import com.itheima.service.db.LogService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class LogManager {

    @Reference
    private LogService logService;

    /**
     * 查询日志列表
     * @param pageNum
     * @param pageSize
     * @param userId
     * @return
     */
    public PageBeanVo findLogList(Integer pageNum, Integer pageSize,Long userId) {
        PageBeanVo pageBeanVo = logService.findLogList(pageNum,pageSize,userId);
        List<Log> logList = (List<Log>) pageBeanVo.getItems();
        if (CollectionUtil.isNotEmpty(logList)){
            for (Log log : logList) {
                if (StrUtil.equals(log.getType(),"0101")){
                    log.setType("登陆");
                }else if (StrUtil.equals(log.getType(),"0102")){
                    log.setType("注册");
                }else if (StrUtil.equals(log.getType(),"0201")){
                    log.setType("发动态");
                }else if (StrUtil.equals(log.getType(),"0202")){
                    log.setType("浏览动态");
                }else if (StrUtil.equals(log.getType(),"0203")){
                    log.setType("动态点赞");
                }else if (StrUtil.equals(log.getType(),"0204")){
                    log.setType("动态喜欢");
                }else if (StrUtil.equals(log.getType(),"0205")){
                    log.setType("评论");
                }else if (StrUtil.equals(log.getType(),"0206")){
                    log.setType("动态取消点赞");
                }else if (StrUtil.equals(log.getType(),"0207")){
                    log.setType("动态取消喜欢");
                }else if (StrUtil.equals(log.getType(),"0301")){
                    log.setType("发小视频");
                }else if (StrUtil.equals(log.getType(),"0302")){
                    log.setType("小视频点赞");
                }else if (StrUtil.equals(log.getType(),"0303")){
                    log.setType("小视频取消点赞");
                }else if (StrUtil.equals(log.getType(),"0304")){
                    log.setType("小视频评论");
                }
            }
        }

        System.out.println(pageBeanVo);
        return pageBeanVo;
    }

    /**
     * 删除日志
     * @param id
     */
    public void deleteLog(Long id) {
        logService.deleteLog(id);
    }

    /**
     *  批量删除日志
     * @param ids
     */
    public void deleteLogList(Long[] ids) {
        if (ids!=null&&ids.length!=0){
            for (Long id : ids) {
                logService.deleteLog(id);
            }
        }
    }
}
